package com.ua.open.authentication.controller;

import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * 安全控制器，需要通过登录认证
 * @author Winsy
 *
 */
@Controller
@RequestMapping("/secure/*")
public class SecureController {
	
	/**
	 * 登陆后首页
	 * @return
	 */
	@RequestMapping(value="index.html")
	public ModelAndView index() {
		ModelAndView mnv = new ModelAndView();
		
		Object principal = SecurityContextHolder.getContext()
				.getAuthentication().getPrincipal();
		if (principal instanceof UserDetails) {
			mnv.addObject("principal",principal);
		}
		mnv.setViewName("secure/index");
		return mnv;
	}

}
